layui.use(['layer'],function () {
    var layer=layui.layer;
    var $ = layui.jquery;

    var userid=$('#userid').text();
    var videoUserid=$('#videoUserid').text();
    var videoid=$('#videoid').text();
    var videolike=$('#videolike').text();
    var collid=$('#collid').text();
    if (collid==1)
    {
        var css=document.getElementById('collid');
        css.style.backgroundColor="#00FFFF";
    }
    window.sessionStorage.setItem("videoId",videoid);
    window.sessionStorage.setItem("userId",userid);
    $('#return').click(function () {
        $.ajax({
            type: 'post',
            url:'/Anime/userIndex/onload',
            dataType: 'json',
            success:function (res) {
                if (res.code==0)
                {
                    window.location.href = "/Anime/home/main";
                }
                else {
                    layer.msg("返回失败");
                }
            }
        })
    })
    $('#fans0').click(function () {
        if($('#fans0').text()=="取关")
        {
            $.ajax({
                type: 'post',
                url: '/Anime/userIndex/follow?tt='+new Date().getTime(),
                dataType: 'json',
                data: {'userid': userid, 'videoUserid': videoUserid, 'follow': 1},
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg("取关成功");
                        var css=document.getElementById('fans0');
                        css.style.backgroundColor="#00FFFF";
                        css.textContent="关注";
                    } else {
                        layer.msg("取关失败");
                    }
                }
            })
        }
        else
        {
            $.ajax({
                type:'post',
                url:'/Anime/userIndex/follow?tt='+new Date().getTime(),
                dataType:'json',
                data:{'userid':userid,'videoUserid':videoUserid,'follow':0},
                success:function (res) {
                    if(res.code==0)
                    {
                        layer.msg("关注成功");
                        var css=document.getElementById('fans0');
                        css.style.backgroundColor="#FFFF00";
                        css.textContent="取关";
                    }
                    else
                    {
                        layer.msg("关注失败");
                    }
                }
            })
        }

    })
    $('#fans1').click(function () {
        if ($('#fans1').text()=="关注")
        {
            $.ajax({
                type:'post',
                url:'/Anime/userIndex/follow?tt='+new Date().getTime(),
                dataType:'json',
                data:{'userid':userid,'videoUserid':videoUserid,'follow':0},
                success:function (res) {
                    if(res.code==0)
                    {
                        layer.msg("关注成功");
                        var css=document.getElementById('fans1');
                        css.style.backgroundColor="#FFFF00";
                        css.textContent="取关";
                    }
                    else
                    {
                        layer.msg("关注失败");
                    }
                }
            })
        }
        else
        {
            $.ajax({
                type:'post',
                url:'/Anime/userIndex/follow?tt='+new Date().getTime(),
                dataType:'json',
                data:{'userid':userid,'videoUserid':videoUserid,'follow':1},
                success:function (res) {
                    if(res.code==0)
                    {
                        layer.msg("取关成功");
                        var css=document.getElementById('fans1');
                        css.style.backgroundColor="#00FFFF";
                        css.textContent="关注";
                    }
                    else
                    {
                        layer.msg("取关失败");
                    }
                }
            })
        }

    })
//点赞与点踩切换
    var i=0,j=0;
    $('#like').click(function () {
        if (i==0&&j==0)
        {
            $.ajax({
                type:'post',
                url:'/Anime/userIndex/like?tt='+new Date().getTime(),
                dataType:'json',
                data:{'videoLike':videolike,'videoId':videoid,'like':1},
                success:function (res) {
                    if (res.code==0)
                    {
                        layer.msg("点赞成功");
                        var css=document.getElementById('likeid');
                        css.style.backgroundColor="#00FFFF";
                        i=1;
                    }
                    else
                    {
                        layer.msg("点赞失败")
                    }
                }
            })
        }
        else if(i==1)
        {
            layer.msg("你以赞过");
        }
        else if(i==0&&j==1)
        {
            $.ajax({
                type:'post',
                url:'/Anime/userIndex/like?tt='+new Date().getTime(),
                dataType:'json',
                data:{'videoLike':videolike,'videoId':videoid,'like':1},
                success:function (res) {
                    if (res.code==0)
                    {
                        layer.msg("点赞成功");
                        var css=document.getElementById('likeid');
                        css.style.backgroundColor="#00FFFF";
                        i=1;j=0;
                        var css1=document.getElementById('unlikeid');
                        css1.style.backgroundColor="#FFFFFF";
                    }
                    else
                    {
                        layer.msg("点赞失败")
                    }
                }
            })
        }
    })
    $('#unlike').click(function () {
        if (i==0&&j==0)
        {
            $.ajax({
                type:'post',
                url:'/Anime/userIndex/like?tt='+new Date().getTime(),
                dataType:'json',
                data:{'videoLike':videolike,'videoId':videoid,'like':0},
                success:function (res) {
                    if (res.code==0)
                    {
                        layer.msg("不喜欢成功");
                        var css=document.getElementById('unlikeid');
                        css.style.backgroundColor="#00FFFF";
                        j=1;
                    }
                    else
                    {
                        layer.msg("不喜欢失败")
                    }
                }
            })
        }
        else if (j==1)
        {
            layer.msg("你以踩过");
        }
        else if(j==0&&i==1)
        {
            $.ajax({
                type:'post',
                url:'/Anime/userIndex/like?tt='+new Date().getTime(),
                dataType:'json',
                data:{'videoLike':videolike,'videoId':videoid,'like':0},
                success:function (res) {
                    if (res.code==0)
                    {
                        layer.msg("不喜欢成功");
                        var css=document.getElementById('unlikeid');
                        css.style.backgroundColor="#00FFFF";
                        j=1;i=0;
                        var css1=document.getElementById('likeid');
                        css1.style.backgroundColor="#FFFFFF";
                    }
                    else
                    {
                        layer.msg("不喜欢失败")
                    }
                }
            })
        }
    })
    $('#collection').click(function () {
        if (collid==1)
        {
            layer.msg("你以收藏过该视频");
        }
        else
        {
            $.ajax({
                type:'post',
                url:'/Anime/userIndex/collection',
                dataType:'json',
                data:{'videoId':videoid,'userId':userid},
                success:function (res) {
                    if (res.code==0)
                    {
                        layer.msg("收藏成功");
                        var css=document.getElementById('collid');
                        css.style.backgroundColor="#00FFFF";
                    }
                    else if (res.code==300)
                    {
                        layer.msg("你以收藏过该视频");
                    }
                    else layer.msg("收藏失败")
                }
            })
        }
    })
})

